function fill_squad_new_player(player)
{
	team_players = document.squad.team_players;
	team_players.options[team_players.options.length] = new Option(player[0], player[1]);
}

function new_player_squad(champ, team, team_name)
{
	callback = fill_squad_new_player;
	window.open("insert_player.php?champ=" + champ + "&team=" + team + "&team_name=" + team_name, "InsertPlayer", "width=640,height=480,status=yes");
}

function squad_send()
{
	squad_players = getElement("squad_players").getElementsByTagName("select");
	for (var i = 0; i < squad_players.length; ++i)
	{
		if (squad_players[i].options.length)
			squad_players[i].options[0].selected = true;
	}
	document.forms.squad.submit();
}

function select_squad_player(select)
{
	squad_players = getElement("squad_players").getElementsByTagName("select");
	for (var i = 0; i < squad_players.length; ++i)
	{
		if (squad_players[i] != select)
		{
			squad_players[i].options.selectedIndex = -1;
		}
		else
		{
			squad_players[i].options.selectedIndex = 0;
			squad_players[i].focus();
		}
	}
}

function add_all_squad()
{
        team_players = document.squad.team_players;

        for (var i = team_players.length - 1; i >= 0; --i)
        {
                team_players.options[i].selected = 1;
                add_squad_player();
        }
}

function add_squad_player()
{
	team_players = document.squad.team_players;

	if (team_players.options.selectedIndex == -1) return;
	
	squad_players = getElement("squad_players").getElementsByTagName("select");

	for (var i = 0; i < squad_players.length; ++i)
	{
		if (squad_players[i].options.length == 0)
		{
			squad_players[i].options[0] = new Option(team_players.options[team_players.options.selectedIndex].text, team_players.options[team_players.options.selectedIndex].value);
			select_squad_player(squad_players[i]);

			team_players.options[team_players.options.selectedIndex] = null;
			break;
		}
	}
}

function rem_squad_player()
{
	team_players = document.squad.team_players;

	squad_players = getElement("squad_players").getElementsByTagName("select");
	for (var i = 0; i < squad_players.length; ++i)
	{
		if (squad_players[i].options.selectedIndex != -1)
		{
			team_players.options[team_players.options.length] = squad_players[i].options[squad_players[i].options.selectedIndex];
		}
	}
}
